package antidestiny.utilib.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.os.RecoverySystem;
import android.support.annotation.Nullable;
import android.widget.ProgressBar;

import antidestiny.utilib.io.Progress;

/**
 * Created by Hero on 2017/2/6.
 * 自动反映进度的进度条
 */

public class AutoProgressBar extends ProgressBar {
    Progress progress;
    ProgressListener progressListener;
    public AutoProgressBar(Context context, final Progress progress, @Nullable ProgressListener listener) {
        super(context,null,android.R.attr.progressBarStyleHorizontal);
        this.progress=progress;
        this.progressListener=listener;
    }

    @Override
    protected synchronized void onDraw(Canvas canvas) {
        setMax(progress.getMax());
        setProgress(progress.getI());
        if (progressListener!=null&&progress.getI()==progress.getMax()){
            progressListener.atTheEnd();
            progressListener=null;
        }
        super.onDraw(canvas);
    }
    public interface ProgressListener{
        void atTheEnd();
    }
}
